/*
 *  Copyright (C) 2010 takaji
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package examples;

import dakside.csv.CSVFile;
import dakside.csv.CSVFileReader;
import examples.helpers.CSVDump;
import examples.helpers.FileHelper;

/**
 * Example 2: Convert CSV to HTML
 * @author takaji
 */
public class Example2 {

    /**
     * Test convert CSV to HTML
     *
     * @param filename
     */
    public static void testCSVToHTML(String filename) {
        System.out.println("Reading from: " + filename);
        // try to parse the whole file to in-memory object
        CSVFile csv = CSVFileReader.parseFile(filename);
        // dump file data to HTML file
        System.out.println("Writing HTML data to " + filename + ".html");
        FileHelper.writeFile(filename + ".html", CSVDump.dumpHTML(csv));
    }

    /**
     * @param args  the command line arguments
     */
    public static void main(String[] args) {
        // first argument is file name
        // we should have 1 argument here
        if (args.length != 1) {
            System.out.println("Usage:");
            System.out.println("java -jar dakside.csv.jar /path/to/file.csv");
            testCSVToHTML("/home/takaji/testbig.csv");
            return;
        }
        String filename = args[0];
        //read CSV data then convert to HTML
        testCSVToHTML(filename);

        System.out.println("Finished.");
    }
}
